home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / asm / utils / dosinfo / dosinfo.s
Text File  |  1980-01-03  |  8KB  |  422 lines

  1.         incdir        "includes:"
  2.         include        "exec/types.i"
  3.         include        "exec/exec_lib.i"
  4.         include        "exec/exec.i"
  5.         include        "libraries/dos_lib.i"
  6.         include        "libraries/dos.i"
  7.         include        "libraries/dosextens.i"
  8.  
  9. CALLSYS        macro
  10.         ifgt    NARG-1
  11.         FAIL    !!!
  12.         endc
  13.         jsr    _LVO\1(a6)
  14.         endm
  15.  
  16.         section        Skeleton,code
  17.  
  18. Openlibs:    move.l        a0,_args
  19. getlf        tst.b        (a0)
  20.         beq.s        no_lf
  21.         cmp.b        #$a,(a0)+
  22.         bne.s        getlf
  23.         sf.b        -(a0)
  24. no_lf
  25.         
  26.         lea        dsname,a1    a1->lib name
  27.         moveq.l        #0,d0        any version
  28.         CALLEXEC    OpenLibrary    and open it
  29.         move.l        d0,_DOSBase    save base ptr
  30.         beq.s        no_libs        if so quit
  31.         CALLDOS        Output        determine CLI handle
  32.         move.l        d0,STD_OUT    and save it for later
  33.         beq.s        no_libs        quit if there is no handle
  34.         moveq.l        #1,d0        no errors
  35. .error        tst.l        d0        any errors?
  36.         beq.s        no_libs        if so quit
  37.  
  38.          bsr        Main        Your routine
  39.  
  40. no_libs        move.l        _DOSBase,d0        d0=base ptr
  41.         beq.s        .lib_error        quit if 0
  42.         move.l        d0,a1            a1->lib base
  43.         CALLEXEC    CloseLibrary        close lib
  44. .lib_error    rts
  45.  
  46. ************** The main part of the program starts here.
  47.  
  48. ; Get the args and find which drive Number.
  49.  
  50. Main        move.l        _args,a0        a0->df0 name
  51.         bsr        _DoInfo
  52.         
  53.         lea        Header,a0        a0->header text
  54.         bsr        DosMsg
  55.         move.l        #REFinfo,a1        a1->info data
  56.         move.l        id_UnitNumber(a1),d0    d0= drive number
  57.  
  58.         move.l        _args,a0        a0->Drive name
  59.         bsr        DosMsg
  60.         lea        Tab,a0            a0->Tab char
  61.         bsr        DosMsg
  62.  
  63.         move.l        #REFinfo,a1        a1->Info
  64.         move.l        id_NumBlocks(a1),d0    d0=Num blocks
  65.         beq        NoDisk            No blocks
  66.  
  67.  ; Print size (in megs)
  68.  
  69.         moveq        #10,d1
  70.         lsr.l        #1,d0            divide by 2
  71.         lsr.l        d1,d0            divide by 1024
  72.         bsr        ConvAscii        convert
  73.         bsr        Print            Display
  74.         
  75. ; Print the number of blocks used.
  76.  
  77.         move.l        id_NumBlocksUsed(a1),d0      d0=Blocks used
  78.         bsr        ConvAscii        Convert
  79.         bsr        Print            Display
  80.  
  81. ; Print number of blocks free.
  82.         
  83.         move.l        id_NumBlocks(a1),d0    d0=Num blocks
  84.         move.l        id_NumBlocksUsed(a1),d1  d1=Blocks used
  85.         
  86.         sub.l        d1,d0            d0=Free blocks
  87.         bsr        ConvAscii        convert
  88.         bsr        Print            Display
  89.  
  90. ; Print the number of blocks used.
  91.  
  92.         move.l        id_NumBlocks(a1),d1    d1=Num blocks
  93.         move.l        id_NumBlocksUsed(a1),d0  d0=Blocks used
  94.         move.l        d0,d2
  95.         sub.l        d0,d1            d1=Free blocks
  96.         moveq        #100,d0
  97.         mulu        d0,d1            multiply by 100
  98.         divu        d2,d1            no.blocks used
  99.         sub.w        d1,d0
  100.         bsr        ConvAscii        Convert
  101.         bsr        Print            Display
  102.  
  103. ; Print number of errors on the disk.
  104.         
  105.         move.l        id_NumSoftErrors(a1),d0  d0=Num errors
  106.         bsr        ConvAscii        convert
  107.         bsr        Print            Display
  108.         
  109.         Bra        Status            
  110.  
  111. ; Print the values here.
  112.         
  113. Print        lea        AsciiNum,a0        Converted Num
  114.         bsr        DosMsg            Display
  115.         lea        Tab,a0            tab
  116.         bsr        DosMsg
  117.         rts
  118.  
  119. ; Find out disk status and print the infomation.
  120.  
  121. Status        move.l        id_DiskState(a1),d0    d0=Diskstate
  122.         cmpi.l        #80,d0            Compare
  123.         beq.s        Protected    
  124.         
  125.         cmpi.l        #81,d0            compare
  126.         beq.s        Repaired
  127.         
  128.         cmpi.l        #82,d0            compare
  129.         beq.s        Writeable
  130.         
  131. ; The disk is write protected, print the info.
  132.  
  133. Protected    lea        Prot,a0
  134.         bsr        DosMsg
  135.         bra        Diskname
  136.         
  137. ; The disk is being repaired, validated, print the info.
  138.  
  139. Repaired    lea        Rep,a0
  140.         bsr        DosMsg
  141.         bra        Diskname
  142.         
  143. ; The disk is write enabled, print the info.
  144.  
  145. Writeable    lea        Write,a0
  146.         bsr        DosMsg
  147.         
  148. ; Find the disk name and print it.
  149.  
  150. Diskname    move.l        id_VolumeNode(a1),d0    
  151.         
  152.         asl.l        #2,d0
  153.         move.l        d0,a4
  154.         move.l        dl_Name(a4),d0        d0=BPTR
  155.         asl.l        #2,d0            Convert
  156.         move.l        d0,a0            a0->BSTR
  157.         bsr        BPrintNL
  158.         rts
  159.         
  160. ; No disk present print msg and exit.
  161.  
  162. NoDisk        lea        NoMsg,a0        a0->Msg
  163.         bsr        DosMsg
  164.         rts
  165.             
  166. ConvAscii    movem.l        d0/a0-a3,-(sp)
  167.         move.l        d0,DataStream        and store value
  168.         lea        Template,a0        format string
  169.         lea        DataStream,a1        data
  170.         lea        PutChar,a2        subroutine
  171.         lea        AsciiNum,a3        buffer
  172.         CALLEXEC    RawDoFmt        create text string
  173.         moveq.l        #1,d0            no errors
  174.         movem.l        (sp)+,d0/a0-a3
  175. .error        rts
  176. PutChar        move.b        d0,(a3)+        save next character
  177.         rts                    and return
  178.  
  179. ; Function     Subroutine to get disk InfoData.
  180. ; Entry        a0-> Drive name
  181. ; Exit        a0-> Ptr Info
  182. ; Corrupt    a0
  183. ; Note        Dos library must be open. Variable REFinfo_data should
  184. ;        be declared eg: 
  185. ;                REFinfo     ds.b    36
  186.  
  187. _DoInfo        movem.l        d0/d1/d2/d6/d7/a6,-(sp)    save regs
  188.         move.l        a0,a6            copy name
  189.  
  190. ; Lock the file.
  191.         move.l        a6,d1            name
  192.         move.l        #ACCESS_READ,d2        mode
  193.         CALLDOS        Lock
  194.         move.l        d0,d7            save lock
  195.         beq.s        .error
  196.         
  197. ; Now read in the info block.
  198.  
  199.         move.l        d7,d1            d1=Lock
  200.         move.l        #REFinfo,d2        d2=36 bytes for info
  201.         CALLDOS        Info            Get info
  202.     
  203.         move.l        d2,d6
  204.         
  205. ; Unlock the file.
  206.         
  207.         move.l        d7,d1
  208.         CALLDOS        UnLock
  209.         
  210.         move.l        d6,a0            ptr to info data
  211.         
  212. ; Ok got all the info.
  213.  
  214. .error        movem.l        (sp)+,d0/d1/d2/d6/d7/a6
  215.         rts
  216.         
  217.  
  218. ***************    Subroutine to display any message in the CLI window
  219.  
  220. ; Entry        a0 must hold address of 0 terminated message.
  221. ;        STD_OUT should hold handle of file to be written to.
  222. ;        DOS library must be open
  223.  
  224. DosMsg        movem.l        d0-d3/a0-a3,-(sp) save registers
  225.  
  226.         tst.l        STD_OUT        test for open console
  227.         beq        .error        quit if not one
  228.  
  229.         move.l        a0,a1        get a working copy
  230.  
  231. ;--------------    Determine length of message
  232.  
  233.         moveq.l        #-1,d3        reset counter
  234. .loop        addq.l        #1,d3        bump counter
  235.         tst.b        (a1)+        is this byte a 0
  236.         bne.s        .loop        if not loop back
  237.  
  238. ;--------------    Make sure there was a message
  239.  
  240.         tst.l        d3        was there a message ?
  241.         beq.s        .error        if not, graceful exit
  242.  
  243. ;--------------    Get handle of output file
  244.  
  245.         move.l        STD_OUT,d1    d1=file handle
  246.         beq.s        .error        leave if no handle
  247.  
  248. ;--------------    Now print the message
  249. ;        At this point, d3 already holds length of message
  250. ;        and d1 holds the file handle.
  251.  
  252.         move.l        a0,d2        d2=address of message
  253.         CALLDOS        Write        and print it
  254.  
  255. ;--------------    All done so finish
  256.  
  257. .error        movem.l        (sp)+,d0-d3/a0-a3 restore registers
  258.         rts
  259.  
  260. ***************    Converts text string to upper case.
  261.  
  262. ;Entry        a0->start of null terminated text string
  263.  
  264. ;Exit        a0->end of text string ( the zero byte ).
  265.  
  266. ;corrupted    a0
  267.  
  268. ucase        tst.b        (a0)
  269.         beq.s        .error
  270.         
  271. .loop        cmpi.b        #'a',(a0)+
  272.         blt.s        .ok
  273.         
  274.         cmp.b        #'z',-1(a0)
  275.         bgt.s        .ok
  276.         
  277.         subi.b        #$20,-1(a0)
  278.         
  279. .ok        tst.b        (a0)
  280.         bne.s        .loop
  281.         
  282. .error        rts
  283.  
  284.  
  285. ***************    Subroutine to display any message in the CLI window
  286.  
  287. ; Prints a line feed after the message
  288.  
  289. ; Entry        a0 must hold address of 0 terminated message.
  290. ;        STD_OUT should hold handle of file to be written to.
  291. ;        DOS library must be open
  292.  
  293. PrintNL        movem.l        d0-d3/a0-a3,-(sp) save registers
  294.  
  295.         bsr        Print
  296.  
  297. ;--------------    Print a line feed
  298.  
  299.         move.l        STD_OUT,d1
  300.         beq.s        .error
  301.         move.l        #EOL_byte,d2
  302.         moveq.l        #1,d3
  303.         CALLDOS        Write
  304.  
  305. ;--------------    All done so finish
  306.  
  307. .error        movem.l        (sp)+,d0-d3/a0-a3 restore registers
  308.         rts
  309.  
  310.  
  311.  
  312. ;--------------
  313. ;--------------    Routine to print a BSTRING into the CLI, no EOL.
  314. ;--------------
  315.  
  316. ; Entry        a0->BSTR
  317.  
  318. ; Exit        none
  319.  
  320. ; Corrupt    none
  321.  
  322. BPrint        movem.l        d0-d4/a0-a6,-(sp)
  323.  
  324.         moveq.l        #0,d3            clear
  325.         move.b        (a0)+,d3        string length
  326.         beq.s        .done            skip if NULL
  327.         
  328.         move.l        STD_OUT,d1        handle
  329.         move.l        a0,d2            address
  330.         CALLDOS        Write            print it
  331.  
  332. .done        movem.l        (sp)+,d0-d4/a0-a6
  333.         rts
  334.  
  335. ;--------------
  336. ;--------------    Print a BSTR followed by a new line
  337. ;--------------
  338.  
  339. BPrintNL    movem.l        d0-d4/a0-a6,-(sp)
  340.  
  341.         bsr        BPrint
  342.  
  343. ;--------------    Print a line feed
  344.  
  345.         move.l        STD_OUT,d1
  346.         beq.s        .error
  347.         move.l        #EOL_byte,d2
  348.         moveq.l        #2,d3
  349.         CALLDOS        Write
  350.  
  351. .error        movem.l        (sp)+,d0-d4/a0-a6
  352.         rts
  353.  
  354.  
  355. *****************************************************************************
  356. *            Data Section                        *
  357. *****************************************************************************
  358.  
  359. dsname        dc.b        'dos.library',0
  360.         even
  361.  
  362. Template    dc.b        '%ld',0
  363.         even
  364. Tab        dc.b        $09            Tab char
  365.         dc.b        0
  366.         
  367. EOL_byte    dc.b        $0a,$0a            
  368.         even
  369.         
  370. Header        dc.b        $0a
  371.         dc.b        'Unit'            Text
  372.         dc.b        $09            Tab 
  373.         dc.b        'Size'
  374.         dc.b        $09
  375.         dc.b        'Used'
  376.         dc.b        $09
  377.         dc.b        'Free'
  378.         dc.b        $09
  379.         dc.b        'Full'
  380.         dc.b        $09
  381.         dc.b        'Errs'
  382.         dc.b        $09
  383.         dc.b        'Status'
  384.         dc.b        $09,$09
  385.         dc.b        'Name'
  386.         dc.b        $0a            Linefeed
  387.         dc.b        0
  388.  
  389. Prot        dc.b        'Read Only',$09,0
  390.         even
  391.  
  392. Rep        dc.b        'Not validated',$09,0
  393.         even
  394.         
  395. Write        dc.b        'Read/Write',$09,0
  396.         even        
  397.  
  398. NoMsg        dc.b        'No Disk Present',$0a,$0a,0
  399.         even        
  400.         
  401. ;***********************************************************
  402.     SECTION    Vars,BSS
  403. ;***********************************************************
  404.  
  405. _args        ds.l        1
  406. _argslen    ds.l        1
  407.  
  408. _DOSBase    ds.l        1
  409.  
  410. RFfile_lock    ds.l        1
  411. RFfile_info    ds.l        1
  412. RFfile_name    ds.l        1
  413. RFfile_len    ds.l        1
  414. DataStream    ds.l        1
  415. STD_OUT        ds.l        1
  416. AsciiNum    ds.b        40        
  417.         even
  418. REFinfo        ds.b        36
  419.         even
  420.         end
  421.  
  422.